<?php

namespace app\api\controller\event;
use app\api\service\event\CreatorService;
use app\lib\yiyan\Yiyan;
use think\Request;

class Creator
{
    protected $Service;
    public function __construct()
    {
        $this->Service = CreatorService::getInstance();
    }


    /**
     * @auth('查询执行人分配订单列表','执行人管理')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function getOrderList(Request $request){
        $params = $request->get();
        $result = $this->Service->getOrderList($params);
        return writeJson(201, $result, '数据列表');
    }


    /**
     * @auth('查询执行人指定订单作品列表','执行人管理')
     * @param Request $request
     * @param('page','页数','require')
     * @param('order_id','订单id','require')
     * @return \think\response\Json
     */
    public function getEventList(Request $request){
        $params = $request->get();
        $result = $this->Service->getEventList($params);
        return writeJson(201, $result, '数据列表');
    }

    /**
     * @auth('执行人写作','执行人管理')
     * @param Request $request
     * @param('order_id','客户订单id','require')
     * @param('type','类型','require')
     * @param('data','账号数组','require|array')
     * @param('pub_time','发布时间','require')
     * @return \think\response\Json
     */
    public function createEvent(Request $request){
        $params = $request->post();
        $this->Service->createEvent($params);
        return writeJson(201, '', '写作完成');
    }

    /**
     * @auth('执行人编辑','执行人管理')
     * @param Request $request
     * @param('id','写作id','require')
     * @param('app_id','分发账号','require')
     * @param('pub_time','发布时间','require')
     * @return \think\response\Json
     */
    public function updateEvent(Request $request){
        $params = $request->param();
        $this->Service->updateEvent($params);
        return writeJson(201, '', '编辑成功');
    }

    /**
     * @auth('查询分发账号列表','执行人管理')
     * @param Request $request
     * @param('page','页数','require')
     * @return \think\response\Json
     */
    public function getEventAccountList(Request $request){
        $params = $request->get();
        $result = $this->Service->getEventAccountList($params);
        return writeJson(201, $result, '数据列表');
    }


    /**
     * 校验文章唯一
     * @param Request $request
     * @param('content_id','文章id','require')
     * @return \think\response\Json
     */
    public function check(Request $request){
        $params = $request->get();
        $this->Service->check($params);
        return writeJson(201,'','验证通过！');
    }

    /**
     * 查询执行人指定订单作品单条
     * @param Request $request
     * @param('id','文章id','require')
     * @return \think\response\Json
     */
    public function getEvent(Request $request){
        $params = $request->get();
        $res = $this->Service->getEvent($params);
        return writeJson(201,$res,'数据！');
    }


    /**
     * @auth('删除执行人指定文章','执行人管理')
     * @param Request $request
     * @param('id','文章id','require')
     * @return \think\response\Json
     */
    public function deleteEvent(Request $request){
        $params = $request->param();
        $this->Service->deleteEvent($params);
        return writeJson(201,true,'删除成功！');
    }


    /**
     * @auth('随机拉取学习机封面文案图片','执行人管理')
     * @param Request $request
     * @return \think\response\Json
     */
    public function randomStudyImg(Request $request){
        $params = $request->get();
        $result = $this->Service->randomStudyImg($params);
        return writeJson(200,$result,'数据！');
    }

//    /**
//     * @auth('学习机文案','执行人管理')
//     * @param Request $request
//     * @return \think\response\Json
//     */
    public function randomStudyText(Request $request){
        $title = $request->get()['title'];
        $tag_arrs = [];
        $tag_arrs[0] = ['#学习机测评','#学习机怎么选','#学习机','#学习成绩','#科大讯飞'];
        $tag_arrs[1] = ['#步步高','#学而思','#举一反三学习机','#学习成绩','#科大讯飞'];
        $tag_arrs[2] = ['#希沃','#学而思','#学习机首选','#AI精准学','#学习机哪个好'];
        $tag_arrs[3] = ['#同步课程','#学习方法','#学习使我快乐','#学习小帮手'];
        $random_number = random_int(0, 3);

        $text = implode(' ', $tag_arrs[$random_number]);


        $result = (new Yiyan())->studyText($title);

        $result = $result['result'].' '.$text;
        return writeJson(200,$result,'数据！');
    }

    public function store(Request $request){
        $params = $request->post();
        $result = $this->Service->store($params['data']);
        return writeJson(200,$result,'采集完成！');
    }





}
